<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>哇噻网 全球优质设计师纯手工制作产品购物网站</title>
		<meta name="description" content="创意礼物首选网站">
		<meta name="keywords" content="手工制作,购物,设计师,哇塞网">
		<meta name="author" content="haimi">
		<script src="./Public/Home/js/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./Public/Home/js/content.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="./Public/Home/css/content.css"/>
		
{{include file="../Common/head"}}
<!--END head-->
<script type="text/javascript">

	$(function(){
		//购买数量-减少
		$('#buy .num_jian').click(function(){
			var jian=$('.num_input').val();
			jian--;
			if(jian < 0) jian=0;
			$('.num_input').val(jian);
		})
		
		//购买数量-增加
		$('#buy .num_jia').click(function(){
			var stock = $('.storage span').html();
			var jia = $('.num_input').val();
			jia++;
			if(jia>stock) jia=stock;
			$('.num_input').val(jia);
		})
		
	//1.规格选择
	$('.list_chima li').click(function(){
		$(this).addClass('red').siblings().removeClass('red');
		//求出有多少种规格
		var specLen = $('.list_chima').length;
//              				alert(specLen);
		//选中的元素的个数
		var redLen = $('.red').length;
		//如果规格都选择了，就得到所有选中的商品属性id，发异步到货品列表查询，获得结果
		if(redLen == specLen){
			var specID = '';
			$.each($('.red'), function() {
				specID +=$(this).attr('specId') + ',';
			});
		 	gid ={{Q('get.gid')}};
			
			
			
			//异步发送
			$.ajax({
				type:"post",//发送方式
				url:"{{U('Cart/specAjax')}}",//发送到的地方
				data:{spec : specID,gid},//发送的数据
				dataType:'json',
				success:function(phpData){
					$('.num_input').val(0);
					if(phpData){
						$.each(phpData,function(k,v){
							$('.goods_info_right_price_yes span').text(v.shopprice);
							$(".inventory").text(v.inventory);
						})
					}else{
						var shopprice=$("#shopprice").val();//价格还原
						$('.goods_info_right_price_yes span').text(shopprice);
						$(".inventory").text('0');
					}
				}
			});
		}
	});
})
</script>

<!--content-->
<div id="content">
	<div class="left">
		<div class="goodsCate">
			<h3 class="ms_yahei">产品分类</h3>
			<ul>
			{{foreach from="$secondCate" key="$k" value="$v"}}
				<li class="ms_yahei">
					<a href="cate_{{$v['cid']}}.html">{{$v['cname']}}</a>
				</li>
			{{endforeach}}
			</ul>
		</div>
		<div class="goodsHotLove">
			<div class="goodsHotLove_nav ms_yahei">
				<a href="javascript:rankings('1');">最爱排行</a>
				<a href="javascript:rankings('2');">热销排行</a>
			</div>
			<ul class="goodsHotLove_list" style="display: block">
			{{foreach from="$hotData" key="$k" value="$v"}}
				<li>
                	<dl>
                    	<dt><a href="content_{{$v['gid']}}.html"><img src="{{$v['listview']}}" ></a></dt>
                        <dd>
                        	<a href="content_{{$v['gid']}}.html" class="ms_yahei" style="overflow: hidden;">{{$v['gname']}}</a>
                            <br>
                            <span class="ms_yahei">￥{{$v['shopprice']}}元</span>
                        </dd>
                    </dl>
                </li>
            {{endforeach}}
			</ul>
			<ul class="goodsHotLove_list" style="display: none;">
			{{foreach from="$hotRank" key="$k" value="$v"}}
                <li>
                	<dl>
                    	<dt><a href="content_{{$v['gid']}}.html"><img src="{{$v['listview']}}" ></a></dt>
                        <dd>
                        	<a href="content_{{$v['gid']}}.html" class="ms_yahei" style="overflow: hidden;">{{$v['gname']}}</a>
                            <br>
                       		<span class="ms_yahei"> ￥{{$v['shopprice']}}元</span>
                        </dd>
                    </dl>
                </li>
            {{endforeach}}
			</ul>
		</div>
	</div>
	
	<div class="right">
		<div class="right_top">
			<div class="right_top_left">
    			<img src="{{$goodsData['listview']}}" alt="" />
    		</div>
    		<div class="right_top_right">
        		<h2 class="bgname ms_yahei ">{{$brandData['bname']}} {{$goodsData['gname']}}</h2>
        		<p class="goods_info_right_price">
        			<span class="goods_info_right_text">单&nbsp;&nbsp;&nbsp;&nbsp;价：</span>
              		<span class="goods_info_right_price_yes">￥<span>{{$goodsData['shopprice']}}</span></span>
              		<!--隐藏域-->
              		<input type="hidden" name="shopprice" id="shopprice" value="{{$goodsData['shopprice']}}" />
        		</p>
        		<!--<p class="goods_info_right_address_info">
        			<span class="goods_info_right_text">运&nbsp;&nbsp;&nbsp;&nbsp;费：</span>
        		</p>-->
        		<!--<ul class="goods_info_right_address">
        			<li class="store_add">中国	广东省	广州</li>
        			<li class="add_text">至</li>
        			<li class="buyer_add">
        				<span id="now_region">天京市</span>
        				<img src="./Public/Home/images/down_add.jpg" alt="" />
        			</li>
        		</ul>-->
        		<!--<ul class="goods_info_express">
        			<li>快递：10元</li>
        			<li>快递：10元</li>
        		</ul>-->
                <!--<p class="goods_info_right_estimate">
                	<span class="goods_info_right_estimate_text">评&nbsp;&nbsp;&nbsp;&nbsp;价：</span>
                	<span class="godds_info_right_pinjia">
                		好评率97.77%  | 
                		<a href="#">已有224条评价</a>
                	</span>
                </p>-->
                <div class="goods_info_buy">
                	
                {{foreach from="$typeAttrData" key="$k" value="$v"}}
                	<dl class="goods_info_right_guige_one">
                		<dt>{{$v['taname']}}：</dt>
                		<dd>
                			<ul class="list_chima">
                			{{foreach from="$v['value']" key="$k" value="$value"}}	
                				<li specId="{{$value['gaid']}}"><a href="javascript:;"  >{{$value['gavalue']}}</a></li>
            				{{endforeach}}
                			</ul>
                		</dd>
                	</dl>
                {{endforeach}}
                	
                	
                	
                	
                	<dl class="goods_info_right_guige_one" style="margin-top: 3px;">
                		<dt>购买数量：</dt>
                		<dd style="margin-top: 13px" id="buy">
                			<span class="num_jian"><a href="javascript:;">-</a></span>
                			<input type="text" class="num_input" value="0"/>
                			<span class="num_jia"><a href="javascript:;">+</a></span>
                			<span class="storage">
                				库存<span class="inventory">{{$goodsData['stock']}}</span>件
                			</span>
                		
                		</dd>
                	</dl>

                	
                	
                	
                	
                	
                	
                </div>
               
                	
              	
                
                <div class="goodsRightBtn">
                	
                	<!--addcart-->
                	 <div class="join_car">
                	 	<ul class="join_info">
                	 		<li class="join_car_message">宝贝已成功加入到购物车!</li>
                	 		<li class="join_car_count">
                	 			<!--购物车共有<span class="n_kind">5</span>
                	 			种宝贝，合计<span class="n_kind_amount">5777</span>元-->
                	 		</li>
                	 		<li class="pay_button">
                	 			<a href="cart.html"><img src="./Public/Home/images/pay_now.png" alt="" /></a>
                	 		</li>
                	 		<p id="close">关闭</p>
                	 	</ul>
                	 </div>
                	 <script type="text/javascript">
                	 	$(function(){//关闭提示
                	 		$('#close').click(function(){
                	 			$('.join_car').css('display','none');
                	 		})
                	 	})
                	 </script>
                	 
                	 
                	 <!--end addcart-->
                	 
                	 
                	 
	            	<div class="buy">
	            		<i class="iconfont" style="font-size: 30px;">&#xe601;</i>
	            		<a href="javascript:;" id="add">加入购物车</a>
	            	</div>
                </div>
               <!--隐藏区域用于存放用户选择的商品规格组合-->
				<input type="hidden" class="userPesc"  combineID=""  glid="" listview=""/>
				
                <script type="text/javascript">
                	//添加购物车
                	$(function(){
                		//点击class=add时触发事件，组装gid,单价，购买数量
                		$('#add').click(function(){
                		var specLen = $('.list_chima').length;
						//alert(specLen);
						//选中的元素的个数
						var redLen = $('.red').length;
						//如果规格都选择了，就得到所有选中的商品属性id，发异步到货品列表查询，获得结果
						if(redLen != specLen) {//没有选择规格
							alert('请选择要购买的规格！');
							return;
						} 
						
                		var re=Number($(".inventory").html());
                		if(!re){//库存没货时提示没货了
                			alert('没货了');
                			return;
                		}
                		
                		if(redLen == specLen){//获取对应的规格组合属性
							var specID = '';
							$.each($('.red'), function() {
								specID +=$(this).attr('specId') + ',';
							});
						}
                		 var inventory = $('.inventory').text();//获取组合属性库存的数量
                		 var listview = '{{$goodsData['listview']}}';//列表图
                		 var gid = {{Q('get.gid')}};//商品gid
                		 var gname = $('.bgname').html();//获取商品的名称
                		 var price = $('.goods_info_right_price_yes span').html();//获取商品的单价
                		 var num = $('.num_input').val();//获取购买数量的值
                		 if(num ==0){//没有选择数量时
                		 	alert('请选择购买数量')
                		 	return;
                		 }
                		 
                		 var data = {gid,gname,price,num,specID,listview,inventory};
                			$.ajax({
                				type:"post",//传输方式
                				url:"{{U('Cart/add')}}",//传输地址
                				data:{cartData:data},//传输的数据
                				dataType:'json',//返回数据的类型
                				success:function(phpData){
                					if(phpData==0){
                						location.href="{{U('Member/login')}}";
                					}else{
                						$('.join_car').css('display','block');
                					}
                				}
                			});
                		})
                	})
                	
                	
                </script>
                
			</div>	
		</div>
		
		
		
		
		<div class="nav_sp">
		      	<ul>
					<li class="select"><a href="javascript:void(0)">产品详情</a></li>
		           <!-- <li><a href="javascript:void(1)">买家评价</a></li>-->
		        </ul>
      	</div>
      	
      	
      	<div id="tab">
			<div class="goods_info_area" style="display: block;">
				<div style="width: 100%; height: 20px;"></div>
				{{foreach from="$detail" value="$v"}}
					<p class="gap"></p>
					<p><img src="{{$v}}"/></p>
					<p class="gap"></p>
				{{endforeach}}
			</div>
			<div class="comment">
				
			</div>
		</div>	
	</div>
	
	
</div>
<!--END content-->

<!--底部开始-->
<li style="width: 100%;height: auto;overflow: hidden;margin: 0 auto;">{{include file="../Common/footer"}}</li>
<!--底部结束-->	
	</body>
</html>
